// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import {switchColor} from "./SwitchControl";
import ControlScript from "../PublicScript/ControlScript";

const {ccclass, property} = cc._decorator;

@ccclass
export default class ChangeColor extends cc.Component {

    @property({tooltip: "颜色", type: cc.Enum(switchColor)})
    switchSpriteColor: switchColor = switchColor.yellow;
    @property({tooltip: "需要替换的精灵", type: cc.Sprite})
    colorSprite: cc.Sprite[] = [];
    // @property({tooltip: "精灵数组", type: cc.SpriteFrame})
    // spriteFrameList: cc.SpriteFrame[] = [];

    colorList = ["#c5d226", "#cc00ff", "#08f700", "#1854bc", "#f49c0b", "#e31413"];
    spriteFrame = null;


    onLoad () {
        ControlScript.loadRes("Sprite/sprite", (res)=>{
            this.spriteFrame = res;
            this.init();
        })
    }

    start () {

    }

    init(){
        for(let i of this.colorSprite){
            i.spriteFrame = new cc.SpriteFrame(this.spriteFrame);
            i.node.color = new cc.Color().fromHEX(this.colorList[this.switchSpriteColor]);
        }
    }

    // update (dt) {}
}
